<?php

/**
 * Description of SQLHelper
 *
 * @author Rino7
 */

class SQLHelper {
        private static $_instance;
	private $_conn;
	const HOST = "localhost";
	const USER = "root";
	const PASSWORD = "";
	const DB_NAME = "miyagigenerator";
	 
	private function __construct() {
            $this->_conn = new mysqli(self::HOST, self::USER, self::PASSWORD, self::DB_NAME);
	}
	
	public static function getInstance() {
            if(is_null(self::$_instance)) {
                self::$_instance = new SQLHelper();
            }
            return self::$_instance;
	}
	
	private function disconnect() {
            $this->_conn->close();
	}
	
	public function executeDeleteQuery($query)
	{
            $this->_conn->query($query);
            $this->_showError();
            return $this->_conn->affected_rows;
	}
	
	public function executeSaveQuery($query) {
            
            $this->_conn->query($query);
            $this->_showError();
            return $this->_conn->affected_rows;
	}
	
	public function executeSelectQuery($query) {
            $result = $this->_conn->query($query);
	    return $result;
	}
	private function _showError() {
            if($this->_conn->errno > 0) {
                    echo "<br> <font color='red'>Error: " . $this->_conn->error . "</font>";
                    die();
            }
	}
}